package com.ruoyi.project.web.quesDetail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.web.quesDetail.domain.QuesDetail;
import com.ruoyi.project.web.quesDetail.service.IQuesDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 做题记录Controller
 * 
 * @author ruoyi
 * @date 2021-02-04
 */
@Controller
@RequestMapping("/web/quesDetail")
public class QuesDetailController extends BaseController
{
    private String prefix = "web/quesDetail";

    @Autowired
    private IQuesDetailService quesDetailService;

    @RequiresPermissions("web:quesDetail:view")
    @GetMapping()
    public String quesDetail()
    {
        return prefix + "/quesDetail";
    }

    /**
     * 查询做题记录列表
     */
    @RequiresPermissions("web:quesDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuesDetail quesDetail)
    {
        startPage();
        List<QuesDetail> list = quesDetailService.selectQuesDetailList(quesDetail);
        return getDataTable(list);
    }

    /**
     * 导出做题记录列表
     */
    @RequiresPermissions("web:quesDetail:export")
    @Log(title = "做题记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuesDetail quesDetail)
    {
        List<QuesDetail> list = quesDetailService.selectQuesDetailList(quesDetail);
        ExcelUtil<QuesDetail> util = new ExcelUtil<QuesDetail>(QuesDetail.class);
        return util.exportExcel(list, "quesDetail");
    }

    /**
     * 新增做题记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存做题记录
     */
    @RequiresPermissions("web:quesDetail:add")
    @Log(title = "做题记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QuesDetail quesDetail)
    {
        return toAjax(quesDetailService.insertQuesDetail(quesDetail));
    }

    /**
     * 修改做题记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QuesDetail quesDetail = quesDetailService.selectQuesDetailById(id);
        mmap.put("quesDetail", quesDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存做题记录
     */
    @RequiresPermissions("web:quesDetail:edit")
    @Log(title = "做题记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuesDetail quesDetail)
    {
        return toAjax(quesDetailService.updateQuesDetail(quesDetail));
    }

    /**
     * 删除做题记录
     */
    @RequiresPermissions("web:quesDetail:remove")
    @Log(title = "做题记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(quesDetailService.deleteQuesDetailByIds(ids));
    }
}
